package com.shujia.scala

import java.io.{BufferedReader, FileReader}
import scala.io.{BufferedSource, Source}

object Demo3IO {
  def main(args: Array[String]): Unit = {
    /**
     * java 输入输出流
     */
    val bufferedReader: BufferedReader = new BufferedReader(new FileReader("data/students.txt"))
    //读取第一行
    var line: String = bufferedReader.readLine()
    while (line != null) {
      println(line)
      //读取下一行
      line=bufferedReader.readLine()
    }
    bufferedReader.close()


    /**
     * scala读取数据方法
     */
    val bufferedSource: BufferedSource = Source.fromFile("data/students.txt")

    //读取所有行返回一个迭代器
    val lines: Iterator[String] = bufferedSource.getLines()

    //将迭代器转换成集合
    val students: List[String] = lines.toList
    println(students)

  }

}
